import {
	getUser
} from "@/api/user.js"
export default {
	namespaced: true,
	state: { //存放状态
		_id: '',
		info: {},
		isLogin: false,
	},
	mutations: {
		GET_ID(state, value) {
			state._id = value
		},
		GET_INFO(state, value) {
			state.info = value
		},
		GET_LOGIN(state, value) {
			state.isLogin = true
		}

	},
	actions: {

		async getUserInfo({
			commit
		}) {
			let res = await getUser()
			if (res.code == 200) {
				commit('GET_INFO', res.data)
				commit('GET_LOGIN')
			} else if (res.code == 401) {
				uni.showToast({
					title: '请先登录',
					icon:'none'
				})
				setTimeout(() => {
					uni.hideToast()
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}, 1000)
			}
			return res


		}

	}
}
